<!-- 物品类型列表 -->
{include file="common:header" /}
<link rel="stylesheet" href="/assets/plugins/bower_components/bootstrap-datetimepicker/bootstrap-datetimepicker.css">
{include file="common:side" /}
    <div id="page-wrapper">
      <!--*************************** content部分开始 ******************-->
      <div class="container-fluid" id="m_main">
        <div class="row m-t-20">
          <div class="col-sm-12">
            <div class="white-box">
              <h2 class="box-title">物品类型管理</h2>
            </div>
            <div class="white-box">
              <form action="">
                <div class="row">
                  <div class="col-sm-6">
                    <div class="form-group">
                      <label class="control-label">物品名称</label>
                      <input type="text" class="form-control" placeholder="填写" v-model="name">
                    </div>
                  </div>
                </div>
                <div class="form-actions m-b-30">
                  <button type="button" class="btn btn-info m-t-10" @click="submitEvent">添加</button>
                </div>
              </form>
              <div class="table-responsive">
                <table id="myTable" class="table table-striped color-table info-table">
                  <thead>
                    <tr>
                      <th>序号</th>
                      <th>物品名称</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr v-for="(item,index) in dataList">
                      <td>{{item.id}}</td>
                      <td>{{item.name}}</td>
                      <td>
                        <div>
                          <a class="info m-r-10" href="javascript:void(0)" @click="editInfo(item.id)">编辑</a>
                          <span class="danger edit" data-toggle="modal" data-target="#confirm1" @click="delId=item.id">删除</span>
                        </div>
                      </td>
                    </tr>
                  </tbody>
                </table>
                <pagination :tr-all="trAll" :page-cur="pageCur" :page-all="pageAll" :page-size="pageSize" @page-to="pageTo" ref="c1"></pagination>
              </div>
              <!-- 确认取消提示框 -->
              <confirm  class="modal fade" id="confirm1" tabindex="-1" role="dialog" :confirm-msg="confirmMsg" :edit-id="delId" @yes-btn="deleteItem"></confirm>
            </div>
          </div>
        </div>
        <!-- /.row -->
      </div>
      <!--*************************** content部分结束 ******************-->

      <!-- <footer class="footer text-center"> 2017 &copy; Ample Admin brought to you by themedesigner.in </footer> -->
    </div>
  </div>
  {include file="common:js" /}
  <script type="text/javascript" src="/web/js/search_list.js"></script>
  {include file="common:footer" /}
  {include file="component:pagination" /}
  {include file="component:confirm" /}

  <script type="text/javascript">
    var vm = new Vue({
      el: '#m_main',
      data() {
        return {
          id: '',
          number: undefined,
          name: undefined,
          apiUrl: "",
          searchUrl: "/dashboard/index/item_type_list", //搜索接口
          draw: '', //校验字段
          dataList: [], //搜索列表数据
          trAll: 0, //数据总数
          pageAll: 0, //页码总数
          pageCur: 1, //当前页
          pageSize: 10, //每页数量
          delUrl: '/dashboard/index/delete_line', //删除请求接口
          confirmMsg: '删除当前物品？', //confirm提示框内容
          delId: undefined, //当前删除的零部件编号
        }
      },
      mounted() {
        this.pageTo(1)
      },
      methods: {
        // 搜索当前页并渲染列表
        pageTo(page) {
          var that = this;
          searchList2(that,page,{},(res)=>{

          },(fail)=>{

          },(error)=>{
          })
        },
        // 删除当前行
        deleteItem(){
          var that = this;
          var params = {
            id:that.delId,
            table:'item_type'
          };
          deleteLine(that,params,(res)=>{},(fail)=>{},(err)=>{});
        },
        editInfo(e) {
          var that = this;
          that.id = e;
          that.dataList.map((f, i)=> {
            if(f.id == e) {
              that.name = f.name
            }
          })
        },
        submitEvent() {
          var that = this;
          var param = {
            name: that.name
          }
          if(that.id != '') {
            param.id = that.id
          }
          console.log(param);
          axios.post('/dashboard/index/add_edit_item_type', param,{headers: {'X-Requested-with':'XMLHttpRequest'}}).then(res => {
            // console.log(res);
            if(res.data.ErrorCode == 1){
              //请求成功
              alert(res.data.ErrorMsg);
              that.id = '';
              that.name = '';
              that.pageTo(that.pageCur)
            }else{
              alert(res.data.ErrorMsg)
            }
          }).catch(err => {
            console.log(err);
          })
        }
      }
    })
  </script>
</body>

</html>
